package com.e.takeaway;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.e.takeaway.adapter.SearchAdapter;
import com.e.takeaway.po.Food;
import com.e.takeaway.po.MerChant;

import java.util.ArrayList;
import java.util.List;

public class SearchActivity extends AppCompatActivity {
    private ListView listView;
    private SearchAdapter searchAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_search);
        getSupportActionBar().hide();
        Bundle bundle = getIntent().getExtras();
        ArrayList list = bundle.getParcelableArrayList("listMerchant");
        List<MerChant> merChants = (List<MerChant>)list.get(0);
        listView = (ListView) findViewById(R.id.list_search);
        searchAdapter = new SearchAdapter(this,merChants);
        listView.setAdapter(searchAdapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                MerChant merChant = merChants.get(i);
                Intent intent = new Intent(SearchActivity.this, DetailActivity.class);
                Bundle b = new Bundle();
                b.putSerializable("mer",merChant);
                intent.putExtras(b);
                startActivity(intent);
            }
        });

    }
}